"""
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.replace.html
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.replace.html
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html
"""
import numpy as np
import pandas as pd
import seaborn as sns
from python_ai.common.xcommon import sep
import re

pd.set_option('display.max_rows', None, 'display.max_columns', None, 'display.max_colwidth', 1000, 'display.expand_frame_repr', False)

sep('load titanic')
df_all = sns.load_dataset('titanic', cache=True)
df = df_all[:5]
print(df)

sep('replace C=>Class_C')
df1 = df.replace('C', 'Class_C')
print(df1)
print(df1.info())

sep('replace 0=>Zero')
df2 = df1.replace(0, 'Zero')  # survived int64 => object
print(df2)
print(df2.info())

sep('replace class First=>1st, Second=>2nd, Third=>3rd in copy')
df_cp = df.copy()
df_cp['class'].replace(dict(First='1st', Second='2nd', Third='3rd'), inplace=True)
print(df_cp)
